﻿using SuperFrame.Charts.SeriesParts;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;


namespace SuperFrame.Charts
{
    /// <summary>
    /// 
    /// </summary>
    public class PartSpline : BasePartLine
    {
        internal Point point;
        internal Point firstControlPoint;
        internal Point endControlPoint;
        internal Path splinePath;

        Ellipse ellipse;
        /// <summary>
        /// 
        /// </summary>
        public PartSpline()
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="startPoint"></param>
        /// <param name="firstControlPoint"></param>
        /// <param name="endControlPoint"></param>
        /// <param name="endPoint"></param>
        public PartSpline(Point point, Point firstControlPoint, Point endControlPoint, string data)
        {
            this.X1 = point.X;
            this.Y1 = point.Y;
            this.point = point;
            this.firstControlPoint = firstControlPoint;
            this.endControlPoint = endControlPoint;
            this.Data = data;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        //public override UIElement CreatePart()
        //{
        //    PathFigure pf = new PathFigure();

        //    pf.StartPoint = startPoint;

        //    BezierSegment bs = new BezierSegment(firstControlPoint, endControlPoint, endPoint, true);
        //    bs.IsSmoothJoin = true;
            
        //    pf.Segments.Add(bs);

        //    PathFigureCollection pfc = new PathFigureCollection();
        //    pfc.Add(pf);
        //    PathGeometry pg = new PathGeometry(pfc);

        //    splinePath = new Path();
        //    splinePath.Stroke = Brushes.Black;
        //    splinePath.Data = pg;
        //    SetBindingForStrokeandStrokeThickness(splinePath);
        //    return splinePath;
        //}
        public override BezierSegment CreatePath()
        {
            BezierSegment bs = new BezierSegment(firstControlPoint, endControlPoint, point, true);
            bs.IsSmoothJoin = true;
            return bs;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override UIElement CreatePoint()
        {
            ellipse = new Ellipse();
            ellipse.Height = 6;
            ellipse.Width = 6;
            ellipse.ToolTip = this.Data;
            ellipse.SetValue(Canvas.LeftProperty, this.X1 - 2.9);
            ellipse.SetValue(Canvas.TopProperty, this.Y1 - 2.9);
            SetBindingForStrokeandFillThickness(ellipse);
            return ellipse;
        }

        public override void Refresh()
        {
            BezierSegment bs = new BezierSegment(firstControlPoint, endControlPoint, point, true);
            bs.IsSmoothJoin = true;

            //PathFigure figure = new PathFigure();
            //BezierSegment bezierPoints = new BezierSegment();
            //PathGeometry pathGeometry = new PathGeometry();
            //figure.StartPoint = startPoint;
            //bezierPoints.Point1 = firstControlPoint;
            //bezierPoints.Point2 = endControlPoint;
            //bezierPoints.Point3 = endPoint;
            //figure.Segments.Add(bezierPoints);
            //pathGeometry.Figures = new PathFigureCollection() { figure };
            //splinePath.Data = pathGeometry;
        }


    }
}
